package cn.tedu.net;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class Test_JDK7 {
    public static void main(String[] args) throws IOException {
//        method();
        method2();
    }
    //jdk7后
    public static void method2(){
        try(
                InputStream in = System.in;
                BufferedInputStream bis = new BufferedInputStream(in);
                ){

        }catch (Exception e){
            e.printStackTrace();
        }

    }
    //jdk7前
    public static void method(){
        //--需求：接收键盘输入的数据，并打印
        InputStream in = null;
        BufferedInputStream bis = null;
        try{
            //1 创建读取流对象
            in = System.in;
             bis = new BufferedInputStream(in);
            //2 开始读取
            int b=0;
            while ((b=bis.read())!=-1){//有数据就读，没数据就返回-1
                System.out.println((char)b);
            }
        }catch (Exception E){
            E.printStackTrace();
        }
        //3释放资源---一定要执行的数据放finally
        finally{
            try {
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
